<!--
* description: 备件价格维护历史查询
* author: xuliwen
* createdDate: 2021-01-21
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-is-show-more-btn="true"
      :dynamic-api-style="'restful'"
      :dynamic-cell-style="columnStyle"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import api from '@/api/pa/apiBaseData'
import { orgApis } from '@/api/pabasicdataapi'
import { exportExcel } from '@/utils/getTimeString.js'
import Vue from 'vue'

export default {
  name: 'PricePartsHistory',

  components: {
    OneTableTemplate
    // Edit: () => import("./edit"),
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      icon: 'el-icon-arrow-down',
      status: false,
      editRowData: {},
      selectiondata: null,
      // 网格查询API配置对象
      apiConfig: api.querySparePartPriceHisList,
      columnStyle({ row, column, rowIndex, columnIndex }) {
        // if(row.headquartersProfitMargin&&row.oemProfitMarginMin&&row.oemProfitMarginH&&row.oemProfitMarginL&&row.dlrProfitMarginL&&row.dlrProfitMarginH&&row.dlrProfitMarginMin){
        // if (columnIndex === 8) {
        //   if (parseFloat(row.headquartersProfitMargin) < row.oemProfitMarginMin) {
        //     return 'background:red'
        //   } else if ((parseFloat(row.headquartersProfitMargin) > row.oemProfitMarginH || parseFloat(row.headquartersProfitMargin) < row.oemProfitMarginL) && parseFloat(row.headquartersProfitMargin) > row.oemProfitMarginMin) {
        //     return 'background:yellow'
        //   }
        // } else if (columnIndex === 12) {
        //   if (parseFloat(row.outletProfitMargin) < row.dlrProfitMarginMin) {
        //     return 'background:red'
        //   } else if ((parseFloat(row.outletProfitMargin) > row.dlrProfitMarginH || parseFloat(row.outletProfitMargin) < row.dlrProfitMarginL) && parseFloat(row.outletProfitMargin) > row.dlrProfitMarginMin) {
        //     console.log((parseFloat(row.outletProfitMargin) > row.dlrProfitMarginH || parseFloat(row.outletProfitMargin) < row.dlrProfitMarginL))
        //     return 'background:yellow'
        //   }
        // }
        // }
      },
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        },
        {
          compKey: 'btnKey3',
          type: '',
          size: 'small',
          clickEvent: () => this.exportExcel111(),
          text: '导出',
          name: 'export',
          position: 'left'
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey6',
              labelName: '备件编码：',
              codeField: 'partNo',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey7',
              labelName: '备件名称：',
              codeField: 'partName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey1',
              labelName: '维修类型：',
              codeField: 'partRepairType',
              textField: 'lookupValueName',
              customObj: {
                api: api.queryPartRepairs
              },
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '备件名称码：',
              codeField: 'partNameId',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '备件状态：',
              codeField: 'partStatus',
              customObj: {
                api: api.queryPartStatus
              },
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey4',
              labelName: '供应商：',
              codeField: 'supplierCode',
              textField: 'supplierShortName',
              component: () => import('@/components/ve/multipleSearchInput'),
              type: 'inputText',
              isMust: false,
              dataToObject: {
                // 控制弹窗页面 搜索 网格 元素
                tableComponents: [
                  {
                    compKey: 'compKey1',
                    labelName: '供应商编码：',
                    codeField: 'supplierCode',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  },
                  {
                    compKey: 'compKey2',
                    labelName: '供应商简称：',
                    codeField: 'supplierShortName',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  },
                  {
                    compKey: 'compKey3',
                    labelName: '状态：',
                    codeField: 'isEnable',
                    component: () => import('@/components/org/LookupValue'),
                    oFields: 'statusId,statusText',
                    options: [
                      { statusId: '1', statusText: '启用' },
                      { statusId: '0', statusText: '禁用' }
                    ],
                    type: 'dropdownList',
                    isMust: true,
                    span: 8
                  }
                ],
                formField: {
                  supplierCode: "",
                  supplierShortName: "",
                  isEnable: "",
                },
                tableCols: [
                  {
                    prop: 'supplierCode',
                    label: '供应商编码'
                  },
                  {
                    prop: 'supplierShortName',
                    label: '供应商简称'
                  },
                  {
                    prop: 'supplierFullName',
                    label: '供应商全称'
                  },
                  {
                    prop: 'supplierAddr',
                    label: '详细地址'
                  },
                  {
                    prop: 'linkMan',
                    label: '联系人'
                  },
                  {
                    prop: 'linkManTel',
                    label: '联系电话'
                  },
                  {
                    prop: 'isEnableCn',
                    label: '状态'
                  },
                  {
                    prop: 'remark',
                    label: '备注'
                  }
                ],
                returnField: {
                  prop: 'supplierCode',
                  label: '供应商编码'
                },
                api: orgApis.supplierInformationQueryquery
              },
              span: 6
            },

            {
              compKey: 'compKey8',
              labelName: '适用车型：',
              codeField: 'carConfigIdList',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey9',
              labelName: '有替代件',
              codeField: 'replacePiece',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'statusId,statusText',
              options: [
                { statusId: '1', statusText: '是' },
                { statusId: '0', statusText: '否' }
              ],
              type: 'dropdownList',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey10',
              labelName: '审核通过日期',
              codeField: 'beginDate,endDate',
              component: () => import('@/components/org/datePicker/andtDatePicker'),
              type: 'YYYY-MM-DD',
              dataToObject: { timer: true, thirtyTime: true, hhmmss: true },
              format: 'yyyy-MM-dd',
              dateOptionsType: '0',
              isMul: false,
              isMust: false
            }
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'partId',
              label: '备件ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'partPriceId',
              label: '备件价格ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'partPriceReviewId',
              label: '备件价格审核ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'reviewStatus',
              label: '审核状态',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'isEnable',
              label: '是否启用',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'partNo',
              label: '备件编码'
            },
            {
              prop: 'partName',
              label: '备件名称'
            },
            // {
            //   prop: 'purchasePrice',
            //   label: '采购价'
            // },
            {
              prop: 'costPrice',
              label: '标准成本价'
            },
            {
              prop: 'pointPriceTax',
              label: '正常订单价（含税）',
              hidden: true
            },
            {
              prop: 'prPointPriceNotTax',
              label: '调整后正常订单价',
              width:120
            },
            {
              prop: 'prUrgentOrderPriceNotTax',
              label: '调整后紧急订单价',
              width:120
            },
            {
              prop: 'prUserPrice',
              label: '调整后建议零售价',
              width:120
            },
            {
              prop: 'pointEffectiveDate',
              label: '正常订单价生效日期',
              width: '150px'
            },
            {
              prop: 'userEffectiveDate',
              width: '130px',
              label: '建议零售价生效日期'
            },

            // {
            //   prop: 'headquartersProfitMargin',
            //   label: '总部利润率'
            // },
            //
            //
            //
            // {
            //   prop: 'outletProfitMargin',
            //   label: '网点利润率'
            // },
            //
            // {
            //   prop: 'prPointPriceTax',
            //   label: '未来网点价含税'
            // },
            // {
            //   prop: "prPointPriceTax",
            //   label: "未来网点价含税+",
            // },
            // {
            //   prop: 'pointPriceNotTax',
            //   label: '网点价不含税'
            // },
            // {
            //   prop: 'prUrgentOrderPrice',
            //   label: '未来紧急订单价'
            // },
            // {
            //   prop: 'prPointEffectiveDate',
            //   label: '未来网点价生效日期',
            //   width: '150px'
            // },
            // {
            //   prop: 'prUserPrice',
            //   label: '未来用户价'
            // },
            // {
            //   prop: 'prOutletProfitMargin',
            //   label: '未来网点利润率'
            // },
            // {
            //   prop: 'prUserEffectiveDate',
            //   label: '未来用户价生效日期',
            //   width: '150px'
            // },
            {
              prop: 'partRepairTypeName',
              label: '维修类型'
            },
            {
              prop: 'partNameId',
              label: '备件名称码'
            },
            {
              prop: 'carConfigIdList',
              label: '适用车型'
            },
            {
              prop: 'partStatusCn',
              label: '备件状态'
            },
            {
              prop: 'submitter',
              label: '提交人'
            },
            {
              prop: 'submissionTime',
              label: '提交时间',
              width: '150px'
            },
            {
              prop: 'reviewStatusName',
              label: '审核状态'
            },
            {
              prop: 'reviewer',
              label: '审核人'
            },
            {
              prop: 'reviewTime',
              label: '审核时间',
              width: '150px'
            }
          ],
      // 表单查询数据
      formField: this.$utils.getFormField(
        this,
        {
          beginDate: '',
          endDate: '',
          partRepairType: '',
          partNameCn: '',
          partStatus: '',
          supplierCode: '',
          partNo: '',
          partName: '',
          partNameId:'',
          carConfigIdList: '',
          replacePiece: ''
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      )
    }
  },
  watch: {
    'formField.orderStatus': {
      deep: true,
      handler: function(newV, oldV) {
        console.log('watch中：', newV)
        // this.querybystatus(newV)
        this.queryTable()
      }
    }
  },
  mounted() {
    // 列表查询
    this.queryTable(1)
  },

  methods: {
    exportExcel111() {
      exportExcel(this.formField, api.querySparePartPriceHisExport.APIUrl, api.querySparePartPriceHisExport.ServiceCode, '备件价格维护历史查询')
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
